// pages/recommend/recommend.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg: '',
    songList:[],
    count: 29,
    idList:[],
    imgList:[],
  },
  toPlay: function (e) {
    var musicid = e.currentTarget.dataset.musicid
    var musicindex = e.currentTarget.dataset.musicindex
    console.log(musicindex);
    //idList是js数组类型
    var idList = this.data.idList
    //把数组转为json字符串
    idList = JSON.stringify(idList)
    console.log(idList)
    //路由跳转传参，路由中传递的参数都是字符串类型
    wx.navigateTo({
      url: '/pages/play/play?id=' + musicid + '&idList=' + idList + '&musicindex=' + musicindex,
    })
    // this.music.play()
    this.setData({
      playFlag: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://localhost:3000/personalized/newsong?limit='+ this.data.count,
      success: (res) => {
        console.log(res);
        this.setData({
          songList: res.data.result
        })
        var idList = this.data.idList
        var imgList = this.data.imgList
        for(var i = 0; i < this.data.songList.length; i++){
          idList.push(this.data.songList[i].id)
          imgList.push(this.data.songList[i].picUrl)
        }
        this.setData({
          idList:idList,
          imgList:imgList
        })
  // console.log(this.data.idList);
  console.log(this.data.imgList);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})